<?php

namespace app\common\model;

use think\Model;

class ReadRecord extends Model
{
    // 表名
    protected $name = 'read_record';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [

    ];

    /**
     * 函数用途描述: 插入用户点击书籍详情记录
     * @author: Feng_Ke
     * @date: 2018/12/12 10:07
     */
    public function Add($param){
        $map=[
            'book_id' => $param['book_id'],
            'openid' => $param['openid'],
            'book_name' => $param['book_name'],
            'book_classify' => $param['book_classify'],
            'cover_image' => $param['cover_image'],
            'book_intro' => $param['book_intro'],
            'collection_id' => $param['collection_id'],
        ];
        $data = $this->where($map)->find();
        $last_id = $data['id'];
        if(!$data){
            $param['createtime'] = time();
            $this->data = $param;
            $res = $this->allowField(true)->save();
            if(!$res){
                return false;
            }
            $last_id = $this->getLastInsID();
        }
        return $last_id;
    }
}
